import axios from 'axios'

axios.defaults.baseURL = '/mall-admin-web'

// 接口response拦截器
axios.interceptors.response.use(function (response) {
  // 校验授权失败
  if (response.data.code === 405 || response.data.code === 200) {
    this.$alert(response.data.message, '提示', {
      confirmButtonText: '确定',
      callback: function () {
        if (window.location.hostname === 'test.mall.admin.plateno.com') {
          window.location.href = 'http://111.plateno.com:8080/plateno-privilege-manager/login.jsp?myredirect=http://test.mall.admin.plateno.com:8888'
        } else if (window.location.hostname === 'mall.admin.plateno.com') {
          window.location.href = 'http://sso.plateno.com:1888/weixinlogin.jsp?myredirect=http://o2o.plateno.com'
        } else {
          window.alert('退出')
        }
      }
    })
  }
  // Do something with response data
  return response
}, function (error) {
  // Do something with response error
  return Promise.reject(error)
})
// 用户资源管理
// 获取菜单资源
// 开发环境
var loginInterface
if (process.env.NODE_ENV === 'development') {
  var instance = axios.create({
    baseURL: ''
  })
  loginInterface = (params) => instance.get('/user/menuList.do', {...params})
} else {
  loginInterface = (params) => axios.get('/user/menuList.do', {...params})
}

export const GetMenuList = loginInterface
// 测试环境
// export const GetMenuList = (params) => axios.get('/user/menuList.do', {...params})
// 用户退出登录接口
export const setLogout = (params) => axios.get('/user/logout.do', {...params})
// 获取用户信息
export const getUserInfo = (params) => axios.get('/user/getLoginInfo.do', {...params})
// 商品模块
// 获取商品列表接口
export const GetGoodsList = (params) => axios.post('/TbProduct/list.do', {...params})
// 获取没有库存商品列表
export const GetNoStockGoodsList = (params) => axios.post('/TbProduct/sellOutSkuList.do', {...params})
// 商品下架
export const SetProductDown = (params) => axios.post('/TbProduct/productDown.do', {...params})
// 商品上架
export const SetProductUp = (params) => axios.post('/TbProduct/productUp.do', {...params})
// 设置商品定时下架
export const SetProductTimingDown = (params) => axios.post('/TbProduct/productTimingDown.do', {...params})
// 设置商品定时上架
export const SetProductTimingUp = (params) => axios.post('/TbProduct/productTimingUp.do', {...params})
// 设置删除商品
export const SetProductDelete = (params) => axios.post('/TbProduct/delete.do', {...params})
// 根据类目 获取sku设置
export const getSkuProperty = (params) => axios.post('/TbPropertyName/listAll.do', {...params})
// 获取类目列表
export const getCategoryList = (params) => axios.post('/TbProduct/categoryList.do', {...params})
// 获取供应商列表
export const getProviderList = (params) => axios.post('/TbProvider/list.do', {...params})
// 保存新增/修改商品信息
export const saveGoodsInfo = (params) => axios.post('/TbProduct/save.do', {...params})
// 获取仓库列表信息
export const getStoreList = (params) => axios.post('/TbStore/list.do', {...params})
// 根据productId获取商品信息
export const getProduct = (params) => axios.post('/TbProduct/get.do', {...params})

// 获取营销活动列表
export const getPriceStrategyList = (params) => axios.post('/TbPriceStrategy/list.do', {...params})
// 运营活动启动
export const savePriceStrategyStart = (params) => axios.post('/TbPriceStrategy/start.do', {...params})
// 运营活动停止
export const savePriceStrategyStop = (params) => axios.post('/TbPriceStrategy/stop.do', {...params})
// 运营活动新增或者保存
export const savePriceStrateg = (params) => axios.post('/TbPriceStrategy/save.do', {...params})
// 处理运营活动接口
export const savePriceStrategyConfirmConflict = (params) => axios.post('/TbPriceStrategy/confirmConflict.do', {...params})
// 根据营销活动查询
export const getPriceStrategyById = (params) => axios.post('/TbPriceStrategy/get.do', {...params})

// 获取积分策略列表
export const getPointStrategyList = (params) => axios.post('/TbPointStrategy/list.do', {...params})
// 积分策略保存或更新
export const savePointStrategySave = (params) => axios.post('/TbPointStrategy/save.do', {...params})
// 处理积分策略 商品冲突
export const savePointStrategyConfirmConflict = (params) => axios.post('/TbPointStrategy/confirmConflict.do', {...params})
// 根据积分策略id获取积分策略信息
export const getPointStrategyById = (params) => axios.post('/TbPointStrategy/get.do', {...params})
// 运营活动停止
// export const savePriceStrategyStop = (params) => axios.post('/TbPriceStrategy/stop.do', {...params})
//
// 根据ID，名称 获取商品列表
export const getGoodsListByIdAndTitle = (params) => axios.post('/TbProduct/simpleProductList.do', {...params})
// 根据productIdList查询sku字典数据
export const getSkuListByProductList = (params) => axios.post('/TbProduct/simplSkulist.do', {...params})
